//
//  OpenLockViewController.swift
//  Exchange
//
//  Created by 孟祥群 on 2018/7/4.
//  Copyright © 2018年 common. All rights reserved.
//

import UIKit

class OpenLockViewController: BaseViewController {
    lazy var switBtn:UISwitch = {
        let switchBtn =  UISwitch()
        switchBtn.addTarget(self, action: #selector(switBtnAction), for: UIControlEvents.touchUpInside)
        return switchBtn
    }()
    lazy var line:UIView = {
        let line:UIView = UIView()
        line.themeBackground = ThemeManager.ThemeColorKeys.tabLineColor
        return line
    }()
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.title = kText("设置解屏密码")
        let nameLabel = BaseLabel(style: .oneStyle)
        nameLabel.text = kText("解屏密码")
        nameLabel.font = UIFont.systemFont(ofSize: 15)
        self.view.addSubview(nameLabel)
        nameLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(15)
            make.top.equalToSuperview().offset(20)
        }
        
        
        self.view.addSubview(switBtn)
//        if self.viewModel?.model?.isOpenGoogle != nil {
//            
//            switBtn.isOn = (self.viewModel?.model?.isOpenGoogle)!
//        }
        
        switBtn.snp.remakeConstraints { (make) in
            make.right.equalToSuperview().offset(5)
            make.centerY.equalTo(nameLabel)
            make.width.equalTo(60)
            make.height.equalTo(20)
        }
        switBtn.transform = CGAffineTransform(scaleX: 0.75, y: 0.75)
        
        self.view.addSubview(line)
        line.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(55)
            make.left.equalToSuperview().offset(15)
            make.right.equalToSuperview().offset(-15)
            make.height.equalTo(0.5)
        }
    }
    
    @objc func switBtnAction() {
        if !switBtn.isOn {
            AppSecurityInfo.default.openScreenLock(dic: [:])
            CYMBShow.showMessage(kText("屏锁关闭成功"))
            switBtn.isOn = false
        }else {
        let controller = ScreenLockerViewController()
        controller.style = .ScreenOpen
        self.navigationController?.pushViewController(controller, animated: true)
        }
    }
    
    override func viewWillAppear(_ animated: Bool) {
        AppSecurityInfo.default.readDic()
        if AppSecurityInfo.default.passWordDic[AppSecurityInfo.SecurityInfo.openScreenKey] == "1" {
           switBtn.isOn = true
        }else {
            switBtn.isOn = false
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
